use strict;
use lib qw(../cgi-bin);
use Diva::DB;
my $mbox= 'C:\Documents and Settings\mdr\Application Data\Mozilla\Profiles\default\7e3xkvye.slt\Mail\mail.wigan-warriors.com\temp';

my $dbh= Diva::DB->new;
$dbh->connect({DATABASE_NAME  => "wwcom",
		DATABASE_SERVER    => "localhost",
		DATABASE_TYPE      => "mysql",
		DATABASE_USERNAME  => "wwcom",
		DATABASE_PASSWORD  => "wwcom"});

my $count= 0;
open(FH,"<$mbox");
while (my $line= <FH>) {
	if ($line=~ /X-Failed-Recipients: (.*?)$/) {
		print "$1\n";
		$count++;
		my ($sth,$rv)= $dbh->get(['USER'],['FK_OBJECT_ID','USER_NAME','USER_ACTIVE','USER_UPDATES'],'',"USER_EMAIL=".$dbh->handle->quote($1));
		while (my $reshash= $sth->fetchrow_hashref) {
			print "USER: $reshash->{FK_OBJECT_ID} $reshash->{USER_UPDATES} $reshash->{USER_ACTIVE} $reshash->{USER_NAME}\n";
			$dbh->update('USER',['USER_UPDATES'],['None'],'FK_OBJECT_ID='.$reshash->{FK_OBJECT_ID});
		}
		$sth->finish;
		
	}
}
close(FH);
print "Found $count emails"; 
$dbh->disconnect;